﻿Imports extranet.BE
Imports extranet.DA

Public Class BCQuestao

  Public Shared Function Cadastrar(ByVal objBEQuestao As BEQuestao) As Integer
    Dim objDAQuestao As New DAQuestao
    Return objDAQuestao.Cadastra(objBEQuestao)
  End Function

  Public Shared Sub Atualizar(ByVal objBEQuestao As BEQuestao)
    Dim objDAQuestao As New DAQuestao
    objDAQuestao.Atualiza(objBEQuestao)
  End Sub

  Public Shared Sub Excluir(ByVal objBEQuestao As BEQuestao)
    Dim objDAQuestao As New DAQuestao
    objDAQuestao.Exclui(objBEQuestao)
  End Sub

  Public Shared Function Selecionar(ByVal intIdQuestao As Integer) As List(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao()
    Dim objBEQuestoes As IList(Of BEQuestao) = objDAQuestao.Seleciona(New BEQuestao(intIdQuestao))
    LerAlternativas(objBEQuestoes)
    Return objBEQuestoes
  End Function

  Public Shared Function Selecionar(ByVal strEnunciado As String, ByVal intProvaId As Integer, _
                                    ByVal sortExpression As String, ByVal sortDirection As String) As List(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao
    Dim objBEQuestao As New BEQuestao
    Dim objBEQuestoes As IList(Of BEQuestao)

    objDAQuestao.objQuery.Sort = New BESort(sortExpression, sortDirection)
    objBEQuestao.Enunciado = strEnunciado
    objBEQuestao.ProvaId = intProvaId
    objBEQuestoes = objDAQuestao.Seleciona(objBEQuestao)
    LerAlternativas(objBEQuestoes)
    Return objBEQuestoes
  End Function

  Private Shared Sub LerAlternativas(ByRef objBEQuestoes As List(Of BEQuestao))
    For Each objBEQuestao As BEQuestao In objBEQuestoes
      objBEQuestao.Alternativas = BCAlternativa.Selecionar("", objBEQuestao.Id, "", "")
    Next
  End Sub

  Public Shared Function SelecionarRespostasQuestao(ByVal intIdCandidato As Integer, ByVal intIdProva As Integer) As List(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao
    Dim objBEQuestao As New BEQuestao
    Dim objBEQuestoes As IList(Of BEQuestao)

    objBEQuestao.ProvaId = intIdProva
    objBEQuestoes = objDAQuestao.Seleciona(objBEQuestao)
    For Each objBEQuestao In objBEQuestoes
      If objBEQuestao.EhDissertativa Then
        objBEQuestao.RespostaDissertativa = BCAlternativa.SelecionarRespostaDissertativa(intIdCandidato, intIdProva, objBEQuestao.Id)
        objBEQuestao.RespostaDissertativaCerta = BCAlternativa.StatusRespostaDissertativa(intIdCandidato, intIdProva, objBEQuestao.Id)
      Else
        objBEQuestao.Alternativas = BCAlternativa.SelecionarRespostaQuestao(intIdCandidato, intIdProva, objBEQuestao.Id)
      End If
    Next
    Return objBEQuestoes
  End Function

  Public Shared Function SelecionarRespostasQuestao(ByVal strAluno As String, ByVal intIdProva As Integer) As List(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao
    Dim objBEQuestao As New BEQuestao
    Dim objBEQuestoes As IList(Of BEQuestao)

    objBEQuestao.ProvaId = intIdProva
    objBEQuestoes = objDAQuestao.Seleciona(objBEQuestao)
    For Each objBEQuestao In objBEQuestoes
      If objBEQuestao.EhDissertativa Then
        objBEQuestao.RespostaDissertativa = BCAlternativa.SelecionarRespostaDissertativa(strAluno, intIdProva, objBEQuestao.Id)
        objBEQuestao.RespostaDissertativaCerta = BCAlternativa.StatusRespostaDissertativa(strAluno, intIdProva, objBEQuestao.Id)
      Else
        objBEQuestao.Alternativas = BCAlternativa.SelecionarRespostaQuestao(strAluno, intIdProva, objBEQuestao.Id)
      End If
    Next
    Return objBEQuestoes
  End Function

  Public Shared Function Selecionar1aQuestaoPendente(ByVal objBECandidato As BECandidato) As BEQuestao
    Dim objDAQuestao As New DAQuestao()
    Dim objBEQuestao As BEQuestao = Nothing
    Dim objBEQuestoes As IList(Of BEQuestao) = objDAQuestao.Seleciona1raQuestaoPendente(objBECandidato)
    If objBEQuestoes.Count() > 0 Then
      LerAlternativas(objBEQuestoes)
      objBEQuestao = objBEQuestoes(0)
    End If
    Return objBEQuestao
  End Function

  Public Shared Function SelecionarQuestoesPendentes(ByVal objBECandidato As BECandidato) As IList(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao()
    Return objDAQuestao.SelecionaQuestoesPendentes(objBECandidato)
  End Function

  Public Shared Sub ResponderQuestao(ByVal objBECandidato As BECandidato)
    Dim objDAQuestao As New DAQuestao()
    objDAQuestao.ResponderQuestao(objBECandidato)
  End Sub

  Public Shared Function Selecionar1aQuestaoPendenteAluno(ByVal objBEAluno As BEAluno) As BEQuestao
    Dim objDAQuestao As New DAQuestao()
    Dim objBEQuestao As BEQuestao = Nothing
    Dim objBEQuestoes As IList(Of BEQuestao) = objDAQuestao.Seleciona1raQuestaoPendenteAluno(objBEAluno)
    If objBEQuestoes.Count() > 0 Then
      LerAlternativas(objBEQuestoes)
      objBEQuestao = objBEQuestoes(0)
    End If
    Return objBEQuestao
  End Function

  Public Shared Function SelecionarQuestoesPendentesAluno(ByVal objBEAluno As BEAluno) As IList(Of BEQuestao)
    Dim objDAQuestao As New DAQuestao()
    Return objDAQuestao.SelecionaQuestoesPendentesAluno(objBEAluno)
  End Function

  Public Shared Sub ResponderQuestaoAluno(ByVal objBEAluno As BEAluno)
    Dim objDAQuestao As New DAQuestao()
    objDAQuestao.ResponderQuestaoAluno(objBEAluno)
  End Sub

  Public Shared Function SetStatusRespostaDissertativa(ByVal intIdCandidato As Integer, ByVal intIdProva As Integer, _
                                                       ByVal intIdQuestao As Integer, ByVal intStatus As Integer) As Boolean
    Dim objDAQuestao As New DAQuestao()
    Return objDAQuestao.SetStatusRespostaDissertativa(intIdCandidato, intIdProva, intIdQuestao, intStatus)
  End Function

  Public Shared Function SetStatusRespostaDissertativaAluno(ByVal strAluno As String, ByVal intIdProva As Integer, _
                                                       ByVal intIdQuestao As Integer, ByVal intStatus As Integer) As Boolean
    Dim objDAQuestao As New DAQuestao()
    Return objDAQuestao.SetStatusRespostaDissertativa(strAluno, intIdProva, intIdQuestao, intStatus)
  End Function

End Class